package com.ruoyi.record.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.record.domain.RecordData;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.record.domain.ServiceRecord;
import com.ruoyi.record.service.IServiceRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 跟进记录Controller
 * 
 * @author dj
 * @date 2025-06-27
 */
@RestController
@RequestMapping("/record/record")
public class ServiceRecordController extends BaseController
{
    @Autowired
    private IServiceRecordService serviceRecordService;

    /**
     * 查询跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordData serviceRecord)
    {
//        List<ServiceRecord> list = serviceRecordService.selectServiceRecordList(serviceRecord);
        startPage();
        List<RecordData> list = serviceRecordService.selectList(serviceRecord);
        System.out.println("list"+ list);
        return getDataTable(list);
    }

    /**
     * 导出跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:record:export')")
    @Log(title = "跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceRecord serviceRecord)
    {
        List<ServiceRecord> list = serviceRecordService.selectServiceRecordList(serviceRecord);
        ExcelUtil<ServiceRecord> util = new ExcelUtil<ServiceRecord>(ServiceRecord.class);
        util.exportExcel(response, list, "跟进记录数据");
    }

    /**
     * 获取跟进记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:record:query')")
    @GetMapping(value = "/{recordid}")
    public AjaxResult getInfo(@PathVariable("recordid") Long recordid)
    {
        return success(serviceRecordService.selectServiceRecordByRecordid(recordid));
    }

    /**
     * 新增跟进记录
     */
    @PreAuthorize("@ss.hasPermi('record:record:add')")
    @Log(title = "跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceRecord serviceRecord)
    {
        return toAjax(serviceRecordService.insertServiceRecord(serviceRecord));
    }

    /**
     * 修改跟进记录
     */
    @PreAuthorize("@ss.hasPermi('record:record:edit')")
    @Log(title = "跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceRecord serviceRecord)
    {
        return toAjax(serviceRecordService.updateServiceRecord(serviceRecord));
    }

    /**
     * 删除跟进记录
     */
    @PreAuthorize("@ss.hasPermi('record:record:remove')")
    @Log(title = "跟进记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordids}")
    public AjaxResult remove(@PathVariable Long[] recordids)
    {
        return toAjax(serviceRecordService.deleteServiceRecordByRecordids(recordids));
    }
}
